import { prefix, get, post } from "../requestDecorator";
import userList from "../mockdb/userList";
import * as Koa from 'koa';
@prefix('/user')
export default class User {

  @post('/login')
  async login(ctx: any) {
    const { username } = ctx.request.body
    for (const user of userList) {
      if (user.username === username) {
        return {
          accessToken: username + '-token'
        }
      }
    }
    return ctx.throw(401);
  }


  @get('/userInfo')
  async getUserInfo(ctx: Koa.Context) {
    let token = ctx.request.header.token
    console.log(token)
    return userList
  }

}